import 'package:course_control/config/com_colors.dart';
import 'package:course_control/config/styles.dart';
import 'package:course_control/widgets/backgroud_widget.dart';
import 'package:course_control/widgets/primary_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_utils/flutter_utils.dart';

import 'package:get/get.dart';

import '../controllers/setting_controller.dart';

class SettingView extends GetView<SettingController> {
  const SettingView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: BackgroundWidget(
        child: Column(
          children: [
            AppBar(
              elevation: 0,
              leading: const SizedBox(),
              backgroundColor: Colors.transparent,
              centerTitle: true,
              title: const Text('设置'),
            ),
            Expanded(
              child: Container(
                padding: EdgeInsets.symmetric(
                    horizontal: 40.ratio, vertical: 50.ratio),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    PrimaryButton(
                      width: 290.ratio,
                      height: 60.ratio,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          Icon(
                            Icons.arrow_back_ios_new,
                            size: 30.ratio,
                            color: Colors.white,
                          ),
                          InkWell(
                            onTap: () {
                              Get.back();
                            },
                            child: Text(
                              '返回上级界面（22s）',
                              style: TextStyles.titleStyle
                                  .copyWith(fontSize: 20.ratio),
                            ),
                          ),
                        ],
                      ),
                    ),
                    SizedBox(
                      height: 20.ratio,
                    ),
                    Container(
                      height: 438.ratio,
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(16.ratio),
                      ),
                      padding: EdgeInsets.all(40.ratio),
                      child: Column(
                        children: [
                          Row(
                            children: [
                              Text(
                                '相关设备信息',
                                style: TextStyle(
                                    fontSize: 24.ratio,
                                    fontWeight: FontWeight.bold),
                              ),
                              const Spacer(),
                              PrimaryButton.border(
                                width: 120.ratio,
                                height: 48.ratio,
                                radius: 4.ratio,
                                child: Text(
                                  '检查更新',
                                  style: TextStyle(
                                      fontSize: 24.ratio,
                                      color: YJColors.subBlue),
                                ),
                              ),
                            ],
                          ),
                          SizedBox(
                            height: 30.ratio,
                          ),
                          Expanded(child: _buildContent())
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget _buildContent() {
    return SizedBox(
      width: double.infinity,
      child: Wrap(
        spacing: 10.ratio,
        direction: Axis.vertical,
        runSpacing: 200.ratio,
        children: [
          _buildItem('中控硬件版本：', '2.1.2'),
          _buildItem('中控固件版本：', '2.1.2'),
          _buildItem('面板硬件版本：', '2.1.2'),
          _buildItem('面板软件版本：', '2.1.2'),
          _buildItem('面板MAC地址：', '2156346615'),
          _buildItem('教师机MAC地址：', '2156346466'),
          _buildItem('教师机IP地址：', '192.168.1.3'),
          _buildItem('服务器地址：', 'app.winworld.com'),
        ],
      ),
    );
  }

  Widget _buildItem(String title, String value) {
    return Text.rich(
      TextSpan(
        text: title,
        children: [
          TextSpan(
            text: value,
            style: const TextStyle(color: YJColors.subBlue),
          ),
        ],
      ),
      style: TextStyle(
        fontSize: 24.ratio,
      ),
    );
  }
}
